import { Component, OnInit, ViewChildren, QueryList } from '@angular/core';
import { TurboperHistory } from "../../../entity/turboper-history.model";
import { OverhaulTableComponent } from "../farm-overhaul/overhaul-table/overhaul-table.component"
import { TurboperHistoryService } from "../../../service/turboper-history.service"
@Component({
  selector: 'app-company-overhaul',
  templateUrl: './company-overhaul.component.html',
  styleUrls: ['./company-overhaul.component.css']
})
export class CompanyOverhaulComponent implements OnInit {
  @ViewChildren(OverhaulTableComponent)
  overhaultables: QueryList<OverhaulTableComponent>;
  active: number = 0;
  startDate: Date = new Date();
  turboperHistorys: TurboperHistory[];
  turboperHistorys2: TurboperHistory[];
  completd: Completd;
  completd2: Completd;
  isEdit: boolean = false;
  currentHistory: TurboperHistory;
  display: boolean = false;
  mes: string;
  completeIndex: number = 0;
  completeName: string = "notCompleted";
  /**
   *日期格式化
   *
   * @type {*}
   * @memberof CompanyOverhaulComponent
   */
  en: any;
  constructor(
    private turboperHistoryService: TurboperHistoryService
  ) { }

  ngOnInit() {
    this.en = {
      firstDayOfWeek: 0,
      dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
      dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
      dayNamesMin: ['日', '一', '二', '三', '四', '五', '六'],
      monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
      monthNamesShort: ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'],
      today: '今天',
      clear: '清除'
    };
    this.getData();
  }
  getData() {
    //非计划
    this.turboperHistoryService.getTurboperHistByStartTime(this.startDate, "02")
      .then(res => {
        if (res) {
          this.completd = res;
          this.turboperHistorys = this.completd[this.completeName]
        }

      })
    //计划停机
    this.turboperHistoryService.getTurboperHistByStartTime(this.startDate, "01")
      .then(res => {
        if (res) {
          this.completd2 = res;
          this.turboperHistorys2 = this.completd2[this.completeName]

        }

      });

  }
  onClickHeader(n: number) {
    this.active = n;
  }
  onComplete(n: number) {
    this.completeIndex = n;
    if (n) {
      this.completeName = "completed";
    } else {
      this.completeName = "notCompleted";
    }
    this.turboperHistorys = this.completd[this.completeName]
    this.turboperHistorys2 = this.completd2[this.completeName]
  }
  onColseEdit(ev) {
    this.isEdit = false;
    if (ev) {
      this.mes = "数据更新成功"
      this.display = true;
    }
  }
  onSelectHistory(ev) {
    this.currentHistory = ev;

    if (!this.currentHistory) {
      this.mes = "没有选中数据"
      return this.display = true;
    }
    this.isEdit = true;

  }
  onSearch() {
    this.getData()
  }
  onEdit() {
    this.overhaultables.forEach((o, i) => {
      if (i == this.active) {
        o.emitSelector()
      }
    })
  }
}
export interface Completd {
  completed: TurboperHistory[],
  notCompleted: TurboperHistory[],
}


// WEBPACK FOOTER //
// ./src/app/module/data-analysis/company-overhaul/company-overhaul.component.ts